package com.xh.bussiness.permission.controller;

import com.xh.bussiness.permission.bean.request.RoleRequest;
import com.xh.bussiness.permission.service.IRoleService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = "角色接口")
@RestController
@RequestMapping("/permission/role")
public class RoleController extends BaseController {

    @Autowired
    private IRoleService roleService;


    @ApiOperation(value = "角色查询",notes = "角色查询")
    @PostMapping("/queryAll")
    public AjaxResult queryAll(RoleRequest bean){
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, "",roleService.queryRole(bean));
    }


    @ApiOperation(value = "角色分页查询",notes = "角色分页查询")
    @RequestMapping("/queryPage")
    public XhPage queryPage(XhPage page, RoleRequest bean){
        return roleService.queryRolePage(page, bean);
    }


    @ApiOperation(value = "新增角色",notes = "新增角色")
    @PostMapping(value="/add")
    @Transactional
    public AjaxResult add(RoleRequest bean){
        String msg=roleService.addRole(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "修改角色",notes = "修改角色")
    @PostMapping(value="/modify")
    @Transactional
    public AjaxResult modify(RoleRequest bean){
        String msg=roleService.modifyRole(bean);
        return new AjaxResult(msg==null,msg);
    }


    @ApiOperation(value = "角色删除",notes = "角色删除")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "角色id",required = true,dataType = "String")
    })
    @PostMapping("/delete")
    @Transactional
    public AjaxResult delete( String id){
        String msg=roleService.deleteRole(id);
        return new AjaxResult(msg==null,msg);
    }

}

